﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Rappelz.GameServer
{
    public interface RegionTester
    {
        void Init(ArPosition OriginalPos, ArPosition TargetPos, float RegionProperty);
        bool IsInRegion(ArPosition pos);
// Function       :   public void RegionTester(const struct RegionTester &)
// Function       :   public void RegionTester()
// Function       :   public struct RegionTester & operator=(const struct RegionTester &)
    }
 
    public class DirectionRegionTester : RegionTester
    {
        public void Init(ArPosition OriginalPos, ArPosition TargetPos, float RegionProperty)
        {
            float m;

            this.dx = TargetPos.x - OriginalPos.x;
            this.dy = TargetPos.y - OriginalPos.y;
            this.c = OriginalPos.x * this.dy - OriginalPos.y * this.dx;
            this.denominator = (float)Math.Sqrt(this.dy * this.dy + this.dx * this.dx);
            this.thickness = RegionProperty * 12.0f * 0.5f;
            float xx = TargetPos.x - OriginalPos.x;
            float yy = TargetPos.y - OriginalPos.y;
            m = (float)Math.Sqrt(yy * yy + xx * xx);
            this.V1x = xx / m;
            this.V1y = yy / m;
            this.ori_x = OriginalPos.x;
            this.ori_y = OriginalPos.y;
        }

        public bool IsInRegion(ArPosition pos)
        {
            float v4;
            float v5;
            float v6;
            double v7;
            bool result;
            float _V2y;
            float _V2ya;
            float _V2yb;
            float _V2yc;
            float _V2yd;
            float _V2ye;

            _V2y = this.dx * pos.y - this.dy * pos.x + this.c;
            _V2ya = (float)Math.Abs(_V2y);
            _V2yb = _V2ya / this.denominator;
            if (_V2yb >= this.thickness)
            {
                result = false;
            }
            else
            {
                v4 = pos.x - this.ori_x;
                _V2yc = pos.y - this.ori_y;
                v5 = _V2yc * _V2yc + v4 * v4;
                v6 = (float)Math.Sqrt(v5);
                _V2yd = _V2yc / v6;
                v7 = _V2yd * this.V1y;
                _V2ye = v4 / v6;
                result = v7 + _V2ye * this.V1x >= 0.0;
            }
            return result;
        }

        float V1x;
        float V1y;
        float ori_x;
        float ori_y;
        float dx;
        float dy;
        float c;
        float thickness;
        float denominator;
    }

    public class CrossRegionTester : RegionTester
    {
        public void Init(ArPosition OriginalPos, ArPosition TargetPos, float RegionProperty)
        {

        }

        public bool IsInRegion(ArPosition pos)
        {
            return false;
        }

    }
    public class ArcCircleRegionTester : RegionTester
    {
        public void Init(ArPosition OriginalPos, ArPosition TargetPos, float RegionProperty)
        {

        }

        public bool IsInRegion(ArPosition pos)
        {
            return false;
        }

    }
    public class CircleRegionTester : RegionTester
    {
        public void Init(ArPosition OriginalPos, ArPosition TargetPos, float RegionProperty)
        {

        }

        public bool IsInRegion(ArPosition pos)
        {
            return true;
        }

    }

}
